package com.canaan.business.controller.pc.agv;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

import com.canaan.business.domain.agv.AgvTaskTemplate;
import com.canaan.business.service.agv.IAgvTaskTemplateService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.core.page.TableDataInfo;
import com.canaan.common.enums.BusinessType;
import com.canaan.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 任务模板Controller
 *
 * @author
 * @date 2023-03-02
 */
@Api(tags = "任务模板")
@RestController
@RequestMapping("/wcs/agvTaskTemplate")
public class AgvTaskTemplateController extends BaseController {
    @Resource
    private IAgvTaskTemplateService agvTaskTemplateService;

    /**
     * 查询任务模板列表
     */
    @ApiOperation(value = "查询任务模板列表")
    @PreAuthorize("@ss.hasPermi('wcs:agvTaskTemplate:list')")
    @GetMapping("/list")
    public TableDataInfo list(AgvTaskTemplate agvTaskTemplate) {
        startPage();
        List<AgvTaskTemplate> list = agvTaskTemplateService.selectAgvTaskTemplateList(agvTaskTemplate);
        return getDataTable(list);
    }

    /**
     * 导出任务模板列表
     */
    @ApiOperation(value = "导出任务模板列表")
    @PreAuthorize("@ss.hasPermi('wcs:agvTaskTemplate:export')")
    @Log(title = "任务模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AgvTaskTemplate agvTaskTemplate) {
        List<AgvTaskTemplate> list = agvTaskTemplateService.selectAgvTaskTemplateList(agvTaskTemplate);
        ExcelUtil<AgvTaskTemplate> util = new ExcelUtil<AgvTaskTemplate>(AgvTaskTemplate.class);
        util.exportExcel(response, list, "任务模板数据");
    }

    /**
     * 获取任务模板详细信息
     */
    @ApiOperation(value = "获取任务模板详细信息")
    @PreAuthorize("@ss.hasPermi('wcs:agvTaskTemplate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(agvTaskTemplateService.selectAgvTaskTemplateById(id));
    }

    /**
     * 新增任务模板
     */
    @ApiOperation(value = "新增任务模板")
    @PreAuthorize("@ss.hasPermi('wcs:agvTaskTemplate:add')")
    @Log(title = "任务模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AgvTaskTemplate agvTaskTemplate) {
        return toAjax(agvTaskTemplateService.insertAgvTaskTemplate(agvTaskTemplate));
    }

    /**
     * 修改任务模板
     */
    @ApiOperation(value = "修改任务模板")
    @PreAuthorize("@ss.hasPermi('wcs:agvTaskTemplate:edit')")
    @Log(title = "任务模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AgvTaskTemplate agvTaskTemplate) {
        return toAjax(agvTaskTemplateService.updateAgvTaskTemplate(agvTaskTemplate));
    }

    /**
     * 删除任务模板
     */
    @ApiOperation(value = "删除任务模板")
    @PreAuthorize("@ss.hasPermi('wcs:agvTaskTemplate:remove')")
    @Log(title = "任务模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(agvTaskTemplateService.deleteAgvTaskTemplateByIds(ids));
    }
}
